<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace Home\Model;
use Think\Model;

/**
 * Description of UserViewModel: User goods view record.
 *
 * @author Dark
 */
class UserViewModel extends Model {
    
    /*
     * 增加一条浏览记录
     */
    public function addViewRecord($data) {
        if(!empty($data)) {
            $this->create();
            return $this->add($data);
        } else {
            Log::write('增加浏览记录传入空值！');
            return FALSE;
        }
    }
    
    /*
     * 删除一条浏览记录
     */
    public function deleteViewRecord($ID) {
        if(!empty($ID)) {
            return $this->where('id='.$ID)->delete();
        } else {
            Log::write('删除浏览记录传入空值！');
            return FALSE;
        }
    }
    
    /*
     * 清空浏览记录按照用户ID
     */
    public function truncateByUserID($UserID) {
        return $this->where('user_ID='.$UserID)->delete();
    }
    
    /*
     * 清空所有浏览记录
     */
    public function truncateTable() {
        $sql = 'TRUNCATE EachGo.t_user_view';
        $this->query($sql);
    }
    
    /*
     * 按照用户ID查询
     */
    public function queryByUserID($ID) {
        if(!empty($ID)) {
            return $this->where('user_ID='.$ID)->select();
        } else {
            Log::write('查询浏览记录用户ID传入空值！');
            return FALSE;
        }
    }
    
    /*
     * 查询所有用户ID
     */
    public function queryAllView(){
        return $this->select();
    }
}
